﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AppLimit.CloudComputing.SharpBox;
using AppLimit.CloudComputing.SharpBox.StorageProvider.DropBox;
using System.Resources;
using System.Reflection;
using CipherBox.Properties;
namespace CipherBox
{
    public partial class SelectFolderDialog : Form
    {
        protected SaveRemotePath m_Callback;
        protected ICloudDirectoryEntry m_CurrentDirectory;
        public string CurrentDirectory { get { return m_CurrentDirectory.Name; } }
        protected DropBox m_dropBox;
        public SelectFolderDialog(DropBox dropBox, SaveRemotePath callback)
        {
            m_Callback = callback;
            m_dropBox = dropBox;
            InitializeComponent();
            ImageList imageListSmall = new ImageList();
            ImageList imageListLarge = new ImageList();
            Image image = Resources.Folder;
            imageListSmall.Images.Add(image);
            imageListLarge.Images.Add(image);
            listView1.LargeImageList = imageListLarge;
            listView1.SmallImageList = imageListSmall;
            show();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            m_Callback(m_dropBox.CurrentDirectory);
            this.Close();
        }

        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void listView1_DoubleClick(object sender, EventArgs e)
        {
            if (listView1.SelectedIndices[0] == 0)
            {
                m_dropBox.BrowseParent();
            }
            else
            {
                m_dropBox.Browse(listView1.Items[listView1.SelectedIndices[0]].Text);
            }

            show();
        }
        private void show()
        {
            listView1.Items.Clear();
            var c = from directory in m_dropBox.GetChildDirectories()
                    select new ListViewItem(directory, 0);
            listView1.Items.Add(new ListViewItem("..", 0));
            listView1.Items.AddRange(c.ToArray<ListViewItem>());

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}
